package net.dodoman.exception;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;

public class Trans {
	public static void main(String[] args) throws Exception {
		try {
			BufferedReader rd = null;
			Writer wr = null;
			try {
				File srcFile = new File((args[0]));
				File dstFile = new File((args[1]));
				rd = new BufferedReader(new InputStreamReader(
						new FileInputStream(srcFile), args[2]));
				wr = new OutputStreamWriter(new FileOutputStream(dstFile),
						args[3]);
				// 注意下面这条语句，它有什么问题吗？
				if (rd == null || wr == null)
					throw new Exception("error! test!");
				while (true) {
					String sLine = rd.readLine();
					if (sLine == null)
						break;
					wr.write(sLine);
					wr.write("\r\n");
				}
			} finally {
				wr.flush();
				wr.close();
				rd.close();
			}
		} catch (IOException ex) {
			ex.printStackTrace();
		}
	}
}